//
//  NetWorTools+find.swift
//  FM
//
//  Created by x on 2017/10/13.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

extension NetWorTools {

    /// 加载find推荐数据
    ///
    /// - Parameters:
    ///   - successCallBack: <#successCallBack description#>
    ///   - errorCallBack: <#errorCallBack description#>
    func loadFindRecommedData(successCallBack:@escaping (_ dataSorce:[FRmd])->(), errorCallBack:@escaping (_ error:Error)->()) -> Void {
        //http://bapi.xinli001.com/fm2/hot_tag_list.json/?flag=4&key=c0d28ec0954084b4426223366293d190&rows=3&offset=0
        let url = "http://bapi.xinli001.com/fm2/hot_tag_list.json"
        let param = ["flag":4,"key":"c0d28ec0954084b4426223366293d190","rows":3,"offset":0] as [String : Any]
        
        get(url, parameters: param, progress: nil, success: { (_, JSON) in
            var models:[FRmd] = [FRmd]()
            let data = (JSON as! [String:AnyObject])["data"]
            
            for dic in data as! [[String:AnyObject]] {
                models.append(FRmd(dict: dic))
            }
            successCallBack(models)
            
        }) { (_, error) in
            errorCallBack(error)
        }
    }
    
    /// 加载find主播数据
    ///
    /// - Parameters:
    ///   - successCallBack: <#successCallBack description#>
    ///   - errorCallBack: <#errorCallBack description#>
    func loadFindAnchorData(successCallBack:@escaping (_ data:[Radio])->(), errorCallBack:@escaping (_ error:Error)->()) -> Void {
        //http://yiapi.xinli001.com/fm/diantai-find-list.json?key=c0d28ec0954084b4426223366293d190&rows=6&offset=0
        let url = "http://yiapi.xinli001.com/fm/diantai-find-list.json"
        let param = ["flag":4,"key":"c0d28ec0954084b4426223366293d190","rows":6,"offset":0] as [String : Any]
        
        get(url, parameters: param, progress: nil, success: { (_, JSON) in
            let data = (JSON as! [String:AnyObject])["data"] as! [[String:AnyObject]]
            var models:[Radio] = [Radio]()
            for dic in data {
                models.append(Radio(dic: dic))
            }
            successCallBack(models)
        }) { (_, error) in
            errorCallBack(error)
        }
    }
    
    //http://bapi.xinli001.com/fm2/broadcast_list.json/?offset=0&key=c0d28ec0954084b4426223366293d190&rows=15&tag=%E7%83%A6%E8%BA%81
//    func laodFindCategoryData(offset:Int, tag:String, finished:(_ data:[])->()) -> <#return type#> {
//        <#function body#>
//    }
}
